<?php
	$brand_id = $params[0];
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$product_code	= strip_tags($_POST['product_code']);
		$url			= stripBlank(strip_tags($_POST['url']));
		$category_id	= $_POST['category_id'];
		$description	= $_POST['description'];
		$keyword		= keyword($description);
		$price			= $_POST['price'];
		$season			= strip_tags($_POST['season']);
		$product_date	= strip_tags($_POST['product_date']);
		$sale			= $_POST['sale'] ? '1': '0';
		$status			= $_POST['status']=='publish' ? '1': '0';
		$ip				= getUserIP();

		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/product/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_basename = basename($upload_fullpath);
		}

		$upload_fieldname	= 'image';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/product/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_image = basename($upload_fullpath);
		}

		$sql = "INSERT INTO `tbl_product` (`product_id`, `product_code`, `title`, `description`, `keyword`, `url`, `category_id`, `brand_id`, `price`, `thumb`, `image`, `season`, `product_date`, `ip`, `date`, `status`, `onsale`) VALUES (NULL, '$product_code', '$title', '$description', '$keyword', '$url', '$category_id', '$brand_id', '$price', '$upload_basename', '$upload_image', '$season', '$product_date', '$ip', NOW(), '$status', '0');";
		mysql_query($sql)or die($sql);
		redirect('../');
		exit;
	}

	$categoryOption	= _u(arrayOptions($cfg['product']['category']),'category');


	include 'ckeditor/ckeditor.php';
	include 'ckeditor/ckfinder/ckfinder.php';
	
	$ckeditor = new CKEditor();
	$ckeditor->returnOutput			= true;
	$ckeditor->basePath				= '/backend/ckeditor/';
	$ckeditor->config['toolbar']	= 'Basic';
	$ckeditor->config['height']		= '100';
	$ckeditor->config['width']		= '600';
	
	CKFinder::SetupCKEditor($ckeditor, '/backend/ckeditor/ckfinder/');
	$introHTML = $ckeditor->editor('description');
?>